package structure.stack.test;

import structure.stack.basic.MyStack;

import java.util.Stack;

/**
 * 项目名称: vital
 * 包 名 称: com.stack.test
 * 类 名 称: Main
 * 类 描 述: TODO
 * 创建时间: 2020/5/25 6:37 下午
 * 创 建 人: Justice
 */
public class Main {
    public static void main(String[] args) {
        MyStack<Integer> myStack = new MyStack<Integer>();
        myStack.push(11);
        myStack.push(12);
        myStack.push(13);
        // System.err.println(myStack.top());
        while (!myStack.isEmpty()) {
            Integer pop = myStack.pop();
            System.err.println(pop);
        }
        Stack<Integer> stack = new Stack<Integer>();
        stack.push(4);
        stack.push(5);
        System.err.println(stack.pop());
    }

    public boolean isValid(String s) {
        int length = s.length();
        Stack<Character> stack = new Stack<Character>();
        for (int i = 0; i < length; i++) {
            char c = s.charAt(i);
            if (c == '(' || c == '[' || c == '{') {
                stack.push(c);
            } else {
                if (stack.isEmpty()) return false;
                Character pop = stack.pop();
                if (pop == '(' && c != ')') return false;
                if (pop == '[' && c != ']') return false;
                if (pop == '{' && c != '}') return false;
            }
        }
        return stack.isEmpty();
    }
}
